package com.kgis.map.feature
{
	import com.kgis.map.common.basetype.UID;
	import com.kgis.map.common.enum.AlignmentEnum;
	import com.kgis.map.common.enum.GeoTypeEnum;
	import com.kgis.map.common.enum.MapActionEnum;
	import com.kgis.map.common.util.Evals;
	import com.kgis.map.common.util.GMath;
	import com.kgis.map.constant.LayerIdConstants;
	import com.kgis.map.events.FeatureEvent;
	import com.kgis.map.geometry.IGeometry;
	import com.kgis.map.geometry.PolylineGeometry;
	import com.kgis.map.geometry.basetype.Extent;
	import com.kgis.map.geometry.basetype.Location;
	import com.kgis.map.geometry.basetype.Pixel;
	import com.kgis.map.layer.FeatureLayer;
	import com.kgis.map.layer.GraphicLayer;
	import com.kgis.map.layer.Layer;
	import com.kgis.map.rule.IRule;
	import com.kgis.map.style.IStyle;
	import com.kgis.map.style.LabelStyle;
	import com.kgis.map.style.PointStyle;
	import com.kgis.map.style.PolygonStyle;
	import com.kgis.map.style.PolylineStyle;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	import mx.collections.ArrayCollection;

	[Bindable]
	[RemoteClass(alias="com.kgis.map.model.vo.Feature")]
	/**
	 * 图形设施类
	 * 包括：设施的符号（点、线、面）、属性、符号显示样式、标注显示样式等
	 */
	public class Feature extends Sprite implements IFeature
	{
		/**featureid*/
		private var _objectId:Number=0;
		/**几何体*/
		private var _geometry:IGeometry=null;
		/**属性map*/
		private var _fieldsMap:Object=null;
		/**标注内容(fieldmap里的某个字段)*/
		private var _labelContent:String=null;
		/**标注文本值*/
		private var _labelText:String=null;
		/**标准显示样式*/
		private var _geoStyle:IStyle=null;
		private var _labelStyle:IStyle=null;
		/**所属图层*/
		private var _layer:Layer=null;
		/**是否选中*/
		private var _selected:Boolean=false;
		/**是否高亮*/
		private var _highLighted:Boolean=false;
		/**是否显示标注*/
		private var _labelVisible:Boolean=true;
		/**是否处于编辑状态*/
		private var _editing:Boolean=false;
		//锁住，不会重新绘制
		private var _isLocked:Boolean=false;

		/**标注**/
		private var markerLabel:TextField=null;
		
		/**特定属性**/
		private var _attributes:Object=null;
		
		
		/**
		 * Constructor class
		 *
		 * @param layer The layer containing the feature.
		 */
		public function Feature(geom:IGeometry=null, attributes:ArrayCollection=null, geostyle:IStyle=null, labelstyle:IStyle=null, labelcontent:String=null)
		{
			this._geometry=geom;
			this._geoStyle=geostyle;
			this._labelStyle=labelstyle;
			this._fieldsMap=attributes;
			this._labelContent=labelcontent;
			//this.cacheAsBitmap=true;
			objectId=UID.gen_pknumber();
		}

		public function get geometry():IGeometry
		{
			return _geometry;
		}

		public function set geometry(value:IGeometry):void
		{
			_geometry=value;
		}

		public function get geoStyle():IStyle
		{
			// 如果为空，先取满足图层规则的， 然后图层缺省的
			var fl:FeatureLayer=this.layer as FeatureLayer;
			if (!_geoStyle)
			{
				var rule:IRule=fl.geoStyleRule;
				if (rule)
				{
					var obj:Object=rule.getRightStyle(this.fieldsMap);
					if (obj)
					{
						return obj as IStyle;
					}
					else
					{
						return fl.geoStyle;
					}
				}
				else
				{
					return fl.geoStyle;
				}
			}
			else
			{
				return _geoStyle;
			}
		}

		public function set geoStyle(value:IStyle):void
		{
			_geoStyle=value;
		}

		public function get labelStyle():IStyle
		{
			// 如果为空，先取满足图层规则的， 然后图层缺省的
			var fl:FeatureLayer=this.layer as FeatureLayer;
			if (!_labelStyle)
			{
				var rule:IRule=fl.labelStyleRule;
				if (rule)
				{
					var obj:Object=rule.getRightStyle(this.fieldsMap);
					if (obj)
					{
						return obj as IStyle;
					}
					else
					{
						return fl.labelStyle;
					}
				}
				else
				{
					return fl.labelStyle;
				}
			}
			else
			{
				return _labelStyle;
			}
		}

		public function set labelStyle(value:IStyle):void
		{
			_labelStyle=value;
		}

		public function get attributes() : Object
		{
			return this._attributes;
		}
		
		public function set attributes(value:Object) : void
		{
			
			this._attributes = value;
			
		}
		
		/**
		 * Events Management
		 *
		 */
		public function onMouseOver(pevt:MouseEvent):void
		{
			this.buttonMode=true;
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_OVER, this, pevt.ctrlKey));
			}

			//设置当前MARKER到最前面
			//this.parent.setChildIndex(this, this.parent.numChildren - 1);

			//发光效果,当在编辑状态中禁用over事件zhxiaomiao
			if(this._layer.map.operateMode!=MapActionEnum.MAP_EDIT){
				this.filters=[(layer as FeatureLayer).glow];
			}
		}

		public function onMouseMove(pevt:MouseEvent):void
		{
			if (this._layer)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_MOUSEMOVE, this, pevt.ctrlKey));
			}
		}

		public function onMouseOut(pevt:MouseEvent):void
		{
			this.buttonMode=false;
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_OUT, this, pevt.ctrlKey));

			}
			this.filters=null;
		}

		public function onMouseClick(pevt:MouseEvent):void
		{
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_CLICK, this, pevt.ctrlKey));

			}
		}

		public function onMouseDoubleClick(pevt:MouseEvent):void
		{
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_DOUBLECLICK, this, pevt.ctrlKey));

			}
		}

		public function onMouseDown(pevt:MouseEvent):void
		{
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_MOUSEDOWN, this, pevt.ctrlKey));
			}
		}

		public function onMouseUp(pevt:MouseEvent):void
		{
			if (this._layer && this._layer.map)
			{
				this._layer.map.dispatchEvent(new FeatureEvent(FeatureEvent.FEATURE_MOUSEUP, this, pevt.ctrlKey));
			}
		}

		public function registerListeners():void
		{
			this.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
			this.addEventListener(MouseEvent.CLICK, this.onMouseClick);
			this.addEventListener(MouseEvent.DOUBLE_CLICK, this.onMouseDoubleClick);
			this.addEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
			this.addEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
			this.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
		}

		public function unregisterListeners():void
		{
			this.removeEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
			this.removeEventListener(MouseEvent.CLICK, this.onMouseClick);
			this.removeEventListener(MouseEvent.DOUBLE_CLICK, this.onMouseDoubleClick);
			this.removeEventListener(MouseEvent.MOUSE_DOWN, this.onMouseDown);
			this.removeEventListener(MouseEvent.MOUSE_UP, this.onMouseUp);
			this.removeEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
		}

		/**
		 * Method to destroy a the feature instance.
		 */
		public function destroy():void
		{
			this.clear();
			this._fieldsMap=null;
			this._geometry=null;
			this._geoStyle=null;
			this._labelStyle=null;
			this._layer=null;
			this.unregisterListeners();
		}

		/**
		 * To obtain feature clone
		 * */
		public function clone():Feature
		{
			return null;
		}

		public function get layer():Layer
		{
			return this._layer;
		}

		public function set layer(value:Layer):void
		{
			this._layer=value;
			if (this._layer != null && selectable)
			{
				registerListeners();
			}
		}

		/**
		 * Determines if the feature is visible on the screen
		 */
		public function onScreen():Boolean
		{
			var onScreen:Boolean=false;

			if (!this._geometry || !this._layer || !this._layer.map)
			{
				return false;
			}

			var currentmapextent:Extent=this.layer.map.extent;
			var featureextent:Extent=this.geometry.getExtent();
			if (currentmapextent.intersectsBounds(featureextent))
			{
				onScreen=true;
			}
			else
			{
				//trace("图层:" + this.layer.layerId.toString() + ",设施:" + this.objectId.toString() + "不在当前地图范围内,设施Extent:"+featureextent.toString()+";地图窗口Extent:"+currentmapextent.toString());
				onScreen=false;
			}

			return onScreen;

		}

		public function get selected():Boolean
		{
			return this._selected;
		}

		public function set selected(value:Boolean):void
		{
			var feaLayer:FeatureLayer=this.layer as FeatureLayer;
			if (value)
			{
				feaLayer.selectedFeatures.push(this);
			}
			else
			{
				var i:Number=feaLayer.selectedFeatures.indexOf(this);
				if (i >= 0)
				{
					feaLayer.selectedFeatures.splice(i, 1);
				}
			}
			this._selected=value;

		}

		public function get highLighted():Boolean
		{
			return this._highLighted;
		}
		
		public function set highLighted(value:Boolean):void
		{
			var feaLayer:FeatureLayer=this.layer as FeatureLayer;
			if (value)
			{
				this.layer.map.highLightFeatures.push(this);
			}
			else
			{
				var i:Number=this.layer.map.highLightFeatures.indexOf(this);
				if (i >= 0)
				{
					this.layer.map.highLightFeatures.splice(i, 1);
				}
			}
			this._highLighted=value;
			this.executeDrawing();
		}
		
		/**
		 * 清除设施图形
		 */
		public function clear():void
		{
			var j:Number=this.numChildren - 1;
			for (j; j > -1; j--)
			{
				this.removeChildAt(j);
			}
			this.graphics.clear();
		}

		/**
		 * 绘制feature
		 */
		public function executeDrawing():void
		{
			if (!_layer)
			{
				trace("objectid:" + this.objectId.toString() + ",layer为空");
				return;
			}
			if (!_geometry)
			{
				trace("layerid:" + this.layer.id + ",objectid:" + this.objectId.toString() + ",geometry为空");
				return;
			}
			if (!this.geoStyle)
			{
				trace("layerid:" + this.layer.id + ",objectid:" + this.objectId.toString() + ",style为空");
				return;
			}
			//清除当前设施及儿子  （除了锚点）
			//this.clear();

			//满足过滤条件的数据才显示
			if (!isFiltered())
			{
				return;
			}

			

			if (this.selected)
			{

				if (this.layer is FeatureLayer)
				{
					if ((this.layer as FeatureLayer).geometryType != GeoTypeEnum.TEXTGEOMETRY)
						this._geometry.draw(this, this.geoSelectStyle, this.layer.map);
				}
				else
				{
					this._geometry.draw(this, this.geoSelectStyle, this.layer.map);
				}

				if (this.layer.labelInRange && this.labelVisible) //标注是否在显示等级范围内
				{
					this.drawText(this.labelSelectedStyle);

				}
			}//增加高亮、hyb
			else if(this.highLighted)
			{
				if (this.layer is FeatureLayer)
				{
					if ((this.layer as FeatureLayer).geometryType != GeoTypeEnum.TEXTGEOMETRY)
						this._geometry.draw(this, this.geoHighLightStyle, this.layer.map);
					//只有featurelayer、静态标注时才高亮
					if (this.layer.labelInRange && this.labelVisible && !(this.layer as FeatureLayer).hasAutoLabel) //标注是否在显示等级范围内
					{
						this.drawText(this.labelHighLightStyle);
					}
				}
				else
				{
					this._geometry.draw(this, this.geoHighLightStyle, this.layer.map);
				}
			}
			else
			{
				
				if (this.layer is FeatureLayer)
				{
					if ((this.layer as FeatureLayer).geometryType != GeoTypeEnum.TEXTGEOMETRY)
						this._geometry.draw(this, this.geoStyle, this.layer.map);
				}
				else
				{
					this._geometry.draw(this, this.geoStyle, this.layer.map);
				}
				
				if (this.layer.labelInRange && this.labelVisible)
				{
					this.drawText(this.labelStyle);
				}
			}

			
		}

		
		
		public function get objectId():Number
		{
			return _objectId;
		}

		public function set objectId(value:Number):void
		{
			_objectId=value;
		}

		/**属性列表（column，value）*/
		public function get fieldsMap():Object
		{
			return _fieldsMap;
		}

		/**
		 * @private
		 */
		public function set fieldsMap(value:Object):void
		{
			_fieldsMap=value;
		}

		/**
		 * 获取标注
		 */
		public function get labelContent():String
		{
			// 如果为空，先取满足图层规则的， 然后图层缺省的
			var fl:FeatureLayer=this.layer as FeatureLayer;
			if (!_labelContent)
			{
				var rule:IRule=fl.labelContentRule;
				if (rule)
				{
					var obj:Object=rule.getRightLabel(this.fieldsMap);
					if (obj)
					{
						return obj as String;
					}
					else
					{
						return fl.labelContent;
					}
				}
				else
				{
					return fl.labelContent;
				}
			}
			else
			{
				return _labelContent;
			}
		}

		public function set labelContent(value:String):void
		{
			_labelContent=value;
		}

		/**选中样式*/
		public function get geoSelectStyle():IStyle
		{
			// 取layer的
			var style:IStyle=(this.layer as FeatureLayer).geoSelectStyle;
			if (style)
			{
				return style;
			}
			else
			{
				if (this.geoStyle is PointStyle)
				{
					var pointstyleclone:PointStyle=this.geoStyle.clone() as PointStyle;
					pointstyleclone.color=0xff0000;
					return pointstyleclone;
				}
				else if (this.geoStyle is PolylineStyle)
				{
					var linestyleclone:PolylineStyle=this.geoStyle.clone() as PolylineStyle;
					linestyleclone.color=0xff0000;
					return linestyleclone;
				}
				else if (this.geoStyle is PolygonStyle)
				{
					var polygonstyleclone:PolygonStyle=this.geoStyle.clone() as PolygonStyle;
					polygonstyleclone.fillColor=0xff0000;
					return polygonstyleclone;
				}
				else
				{
					return null;
				}

			}
		}

		public function get labelSelectedStyle():IStyle
		{
			// 取layer的
			var style:IStyle=(this.layer as FeatureLayer).labelSelectedStyle;
			if (style)
			{
				return style;
			}
			else
			{
				var styleclone:LabelStyle=this.labelStyle.clone() as LabelStyle;
				styleclone.color=0xff0000;
				return styleclone;
			}
		}

		/**高亮样式*/
		public function get geoHighLightStyle():IStyle
		{
			// 取layer的
			var style:IStyle=(this.layer as FeatureLayer).geoHighLightStyle;
			if (style)
			{
				return style;
			}
			else
			{
				if (this.geoStyle is PointStyle)
				{
					var pointstyleclone:PointStyle=this.geoStyle.clone() as PointStyle;
					pointstyleclone.color=0x00ff00;
					return pointstyleclone;
				}
				else if (this.geoStyle is PolylineStyle)
				{
					var linestyleclone:PolylineStyle=this.geoStyle.clone() as PolylineStyle;
					linestyleclone.color=0x00ff00;
					return linestyleclone;
				}
				else if (this.geoStyle is PolygonStyle)
				{
					var polygonstyleclone:PolygonStyle=this.geoStyle.clone() as PolygonStyle;
					polygonstyleclone.fillColor=0x00ff00;
					return polygonstyleclone;
				}
				else
				{
					return null;
				}
				
			}
		}
		public function get labelHighLightStyle():IStyle
		{
			// 取layer的
			var style:IStyle=(this.layer as FeatureLayer).labelHighLightStyle;
			if (style)
			{
				return style;
			}
			else
			{
				var styleclone:LabelStyle=this.labelStyle.clone() as LabelStyle;
				styleclone.color=0x00ff00;
				return styleclone;
			}
		}
		
		public function get selectable():Boolean
		{
			if (!this._layer)
			{
				return (this._layer as FeatureLayer).selectable;
			}
			return true;
		}

		/**是否显示标注*/
		public function get labelVisible():Boolean
		{
			//首先根据所属图层是否显示标注来判断，如果所属图层不显示标注，直接返回false
			if (this._layer)
			{
				if (!((this._layer as FeatureLayer).labelVisible))
				{
					return false;
				}
			}

			//根据属性字段是否有“LABELVISIABLE”字段，如果有，这取这里面的值作为返回值
			if (this.fieldsMap)
			{
				if (this.fieldsMap.hasOwnProperty("LABELVISIABLE"))
				{
					if (this.fieldsMap["LABELVISIABLE"])
					{
						return this.fieldsMap["LABELVISIABLE"];
					}
				}
			}
			return _labelVisible;
		}

		/**
		 * @private
		 */
		public function set labelVisible(value:Boolean):void
		{
			_labelVisible=value;
		}

		/**是否编辑状态*/
		public function get editing():Boolean
		{
			return _editing;
		}

		/**
		 * @private
		 */
		public function set editing(value:Boolean):void
		{
			if (_editing != value && value == false)
			{
				//移除锚点
				if (this.layer.map)
				{
					var anchorLayer:GraphicLayer=this.layer.map.getLayerById(LayerIdConstants.ANCHORLAYER_LAYERID) as GraphicLayer;
					anchorLayer.removeAnchor();
				}
			}

			_editing=value;
		}



		/**绘制静态标注
		 * @param style 标注样式
		 * @param Map 地图控件
		 */
		public function drawText(style:IStyle):void
		{
			if (!this._geometry || !this.layer || !this.layer.map)
			{
				trace("layerid:" + this.layer.id + ",objectid:" + this.objectId.toString() + ",标注数据有错误");
				return;
			}

			var labeltext:String=this.labelText;
			if (!labeltext)
			{
				//trace("objectid:"+this.objectId.toString()+",标注内容为空");
				return;
			}

			if (!style)
			{
				trace("objectid:" + this.objectId.toString() + ",标注样式为空");
				return;
			}

			try
			{
				var tstyle:LabelStyle=style as LabelStyle;
				//根据几何体计算标注位置
				var tlocation:Location;
				if (this.geometry.getGeometryType() == GeoTypeEnum.POLYLINEGEOMETRY) //线的动态标注
				{

					var lineArray:ArrayCollection=GMath.PolyLineTrimByRectangle(PolylineGeometry(this.geometry).pointList, this.layer.map.extent.xmin, this.layer.map.extent.ymin, this.layer.map.extent.xmax, this.layer.map.extent.ymax);
					for each (var polyline:PolylineGeometry in lineArray)
					{
						var screenPoint:Location=null;
						var angle:ArrayCollection=new ArrayCollection();
						var loc:Location=GMath.MidPointOfPolyline(polyline.pointList, angle);
						if (loc == null)
							continue;
						tlocation=loc;
						break;
					}
				}
				if (!tlocation)
				{
					tlocation=this.geometry.getLabelLocation();
				}

				//location不在当前窗口内的不画
				if (!this.layer.map.extent.containsLocation(tlocation, true, this.layer.map.extent.width / 2, this.layer.map.extent.height / 2))
				{
					return;
				}
				var point:Pixel=this.layer.map.getLayerPxFromLocation(tlocation);

				//加上偏移量   偏移量为像素单位
				var nXoffset:Number=tstyle.xoffset;
				var nYoffset:Number=tstyle.yoffset;

				var nRotation:Number=Evals.evalToNumber(this.fieldsMap, tstyle.rotation);
				nRotation=nRotation + this.geometry.getLabelAngle();
				//注：该rotation为标注的垂线与Y轴的夹角       对于线通过this.geometry.getLabelAngle()取得了标注的角度;
				//pixel 坐标上小 下大 与坐标系相反的，所以Y取负值
				nXoffset=nXoffset * Math.cos(-nRotation / 180 * Math.PI) + nYoffset * Math.cos((90 - nRotation) / 180 * Math.PI);
				nYoffset=-nXoffset * Math.sin(-nRotation / 180 * Math.PI) + -nYoffset * Math.sin((90 - nRotation) / 180 * Math.PI);

				var sFontName:String=tstyle.font;

				var nSize:Number=12.0;
				var tempSize:String;
				if (tstyle.size.length > this.layer.map.zoom)
				{
					tempSize=tstyle.size[this.layer.map.zoom];
				}
				else
				{
					tempSize=tstyle.size[0];
				}
				nSize=Evals.getSizeByLevel(tempSize, this.layer.map.zoom);

				var nColor:int=tstyle.color;
				var nAlignMent:int=tstyle.alignment;

				var nAlpha:Number=tstyle.alpha;

				//文本
				//var markerLabel:TextField=new TextField();
				if(!markerLabel)
				{
					markerLabel=new TextField();
					this.addChild(markerLabel);
					
				}
				markerLabel.autoSize="left";
				//markerLabel.border = true;
				markerLabel.rotationZ=nRotation;
				markerLabel.defaultTextFormat=new TextFormat(sFontName, nSize, nColor, false, null, null, null, '_blank', "left");
				markerLabel.mouseEnabled=false;
				markerLabel.alpha=nAlpha;

				//替换自动换行浮
				while (labeltext.indexOf("[br]", 0) >= 0) //如果能找到该字段
				{
					labeltext=labeltext.replace("[br]", "\n");
				}
				markerLabel.text=labeltext;

				if (nAlignMent == AlignmentEnum.LEFTTOP)
				{
					markerLabel.y=point.y + nYoffset;
					markerLabel.x=point.x + nXoffset;
				}
				else if (nAlignMent == AlignmentEnum.MIDETOP)
				{
					markerLabel.y=point.y + nYoffset - markerLabel.textWidth / 2 * Math.cos(Math.PI / 2 - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - markerLabel.textWidth / 2 * Math.sin(Math.PI / 2 - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.RIGHTTOP)
				{
					markerLabel.y=point.y + nYoffset - markerLabel.textWidth * Math.cos(Math.PI / 2 - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - markerLabel.textWidth * Math.sin(Math.PI / 2 - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.LEFTMID)
				{
					markerLabel.y=point.y + nYoffset - markerLabel.textHeight / 2 * Math.cos(0 - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - markerLabel.textHeight / 2 * Math.sin(0 - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.CENTER)
				{
					markerLabel.y=point.y + nYoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight) / 2 * Math.cos(Math.atan(markerLabel.textWidth / markerLabel.textHeight) - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight) / 2 * Math.sin(Math.atan(markerLabel.textWidth / markerLabel.textHeight) - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.RIGHTMID)
				{
					markerLabel.y=point.y + nYoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight / 4) * Math.cos(Math.atan(markerLabel.textWidth * 2 / markerLabel.textHeight) - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight / 4) * Math.sin(Math.atan(markerLabel.textWidth * 2 / markerLabel.textHeight) - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.LEFTBOTTOM)
				{
					markerLabel.y=point.y + nYoffset - markerLabel.textHeight * Math.cos(0 - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - markerLabel.textHeight * Math.sin(0 - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.MIDBOTTOM)
				{
					markerLabel.y=point.y + nYoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth / 4 + markerLabel.textHeight * markerLabel.textHeight) * Math.cos(Math.atan(markerLabel.textWidth * 0.5 / markerLabel.textHeight) - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth / 4 + markerLabel.textHeight * markerLabel.textHeight) * Math.sin(Math.atan(markerLabel.textWidth * 0.5 / markerLabel.textHeight) - nRotation * Math.PI / 180);
				}
				else if (nAlignMent == AlignmentEnum.RIGHTBOTTOM)
				{
					markerLabel.y=point.y + nYoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight) * Math.cos(Math.atan(markerLabel.textWidth / markerLabel.textHeight) - nRotation * Math.PI / 180);
					markerLabel.x=point.x + nXoffset - Math.sqrt(markerLabel.textWidth * markerLabel.textWidth + markerLabel.textHeight * markerLabel.textHeight) * Math.sin(Math.atan(markerLabel.textWidth / markerLabel.textHeight) - nRotation * Math.PI / 180);
				}

				//this.addChild(markerLabel);
			}
			catch (error:Error)
			{
				trace("objectid:" + this.objectId.toString() + error.message);
			}

		}

		/**
		 * 获取该feature的位置，对于点设施为点的位置，对于线设施为线最长段的中点，对于面设施为面的重心
		 */
		public function getLocation():Location
		{
			if (!this._geometry)
			{
				trace("geometry为空，不能获取该feature的location");
				return null;
			}
			return this._geometry.getLabelLocation();
		}

		/**
		 * 是否满足过滤条件
		 * @return
		 *    true--满足条件的显示
		 *    false--不满足条件的不显示
		 */
		public function isFiltered():Boolean
		{
			if (!this.layer)
				return false;

			var feaLayer:FeatureLayer=this.layer as FeatureLayer;
			var datafilter:String=feaLayer.dataFilter;
			if (datafilter)
			{
				return Evals.evalToBoolean(fieldsMap, datafilter);
			}
			else
			{
				return true;
			}
		}

		/**标注值*/
		public function get labelText():String
		{
			if (_labelText)
			{
				return _labelText;
			}

			//转换[]
			var labelvalue:String=this.labelContent;
			if (labelvalue)
			{
				while (labelvalue.indexOf("[") >= 0)
				{
					var t1:int=labelvalue.indexOf("[");
					var t2:int=labelvalue.indexOf("]", t1);
					var field:String=labelvalue.substr(t1 + 1, t2 - t1 - 1);
					var value:String=Evals.evalToString(this.fieldsMap, field);
					labelvalue=labelvalue.replace("[" + field + "]", value);
				}
			}
			return labelvalue;

		}

		/**labelvalue
		 * @private
		 */
		public function set labelText(value:String):void
		{
			_labelText=value;
		}

		/**是否处于录入画图状态*/
		public function get isLocked():Boolean
		{
			return _isLocked;
		}

		/**
		 * @private
		 */
		public function set isLocked(value:Boolean):void
		{
			_isLocked=value;
		}


	}
}


